package com.china08.yxyapi.api.manage.tec.teaching.scoreport.baseanalysis;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.scoreport.Exam;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.scoreport.ExamBaseAnalyseRepository;
import com.china08.yxyapi.service.mg.ExamBaseAnalyseService;

/**
 * 基础分析 生成报告
 * 
 */
@CrossOrigin
@RestController
public class BaseAnalysisReportController {
    @Autowired
    private ExamBaseAnalyseService examBaseAnalyseService;
    @Autowired
    private ExamBaseAnalyseRepository examBaseAnalyseRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/scoreport/baseanalysis/report", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        RespModel model = new RespModel();
        Exam exam = new Exam();
        exam.setId(reqModel.examId);
        String examBaseId = examBaseAnalyseRepository.findByExam(exam).getId();
        List<Object> objs = null;
        if (examBaseId != null && !examBaseId.equals("")) {
            objs = examBaseAnalyseService.getReportMessage(examBaseId, reqModel.examId, reqModel.fineRank);
        } else {
            objs = examBaseAnalyseService.getReportMessage(null, reqModel.examId, reqModel.fineRank);
        }

        model.examStudentModelLst = (List<ExamStudentModel>) objs.get(0);
        model.difficultDegree = (Integer) objs.get(1);// 难度基本
        model.remark = (String) objs.get(2);// 分布分析
        return model;
    }

    protected static class RespModel extends YxyApiRespModel {
        // 学生排名list
        public List<ExamStudentModel> examStudentModelLst;
        // 难度基本: 1-容易 2-一般 3-难 4-非常难
        public Integer difficultDegree;
        // 分布分析
        public String remark;
        
    }

    protected static class ReqModel extends YxyApiReqModel {
        public Map<Integer, Integer> fineRank;
        // 考试的id
        public String examId;
    }

    public class ExamStudentModel {
        // 学生名称
        public String studentNick;
        // 分数
        public Double stuTotalScore;
    }
}
